package com.neu.smty.controller;

import io.swagger.annotations.Api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neu.common.annotation.Log;
import com.neu.common.core.controller.BaseController;
import com.neu.common.core.domain.AjaxResult;
import com.neu.common.core.page.TableDataInfo;
import com.neu.common.enums.BusinessType;
import com.neu.common.utils.poi.ExcelUtil;
import com.neu.smty.domain.CmtAdv;
import com.neu.smty.domain.HealthPackage;
import com.neu.smty.service.IHealthPackageService;
/**
 * 套餐管理Controller
 *
 * @author ljxl
 * @date 2023-09-21
 */
@Api(tags = "套餐管理后台接口")
@RestController
@RequestMapping("/smty/package")
public class HealthPackageController extends BaseController
{
    @Autowired
    private IHealthPackageService healthPackageService;

    /**
     * 查询套餐管理列表
     */
    @PreAuthorize("@ss.hasPermi('smty:package:list')")
    @GetMapping("/list")
    public TableDataInfo list(HealthPackage healthPackage)
    {
        startPage();
        List<HealthPackage> list = healthPackageService.selectHealthPackageList(healthPackage);
        return getDataTable(list);
    }

    /**
     * 导出套餐管理列表
     */
    @PreAuthorize("@ss.hasPermi('smty:package:export')")
    @Log(title = "套餐管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HealthPackage healthPackage)
    {
        List<HealthPackage> list = healthPackageService.selectHealthPackageList(healthPackage);
        ExcelUtil<HealthPackage> util = new ExcelUtil<HealthPackage>(HealthPackage.class);
        return util.exportExcel(list, "package");
    }

    /**
     * 获取套餐管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('smty:package:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(healthPackageService.selectHealthPackageById(id));
    }

    /**
     * 新增套餐管理
     */
    @PreAuthorize("@ss.hasPermi('smty:package:add')")
    @Log(title = "套餐管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthPackage healthPackage)
    {
        return toAjax(healthPackageService.insertHealthPackage(healthPackage));
    }

    /**
     * 修改套餐管理
     */
    @PreAuthorize("@ss.hasPermi('smty:package:edit')")
    @Log(title = "套餐管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthPackage healthPackage)
    {
        return toAjax(healthPackageService.updateHealthPackage(healthPackage));
    }

    /**
     * 删除套餐管理
     */
    @PreAuthorize("@ss.hasPermi('smty:package:remove')")
    @Log(title = "套餐管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(healthPackageService.deleteHealthPackageByIds(ids));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('smty:package:edit')")
    @Log(title = "套餐管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody HealthPackage healthPackage)
    {
        return toAjax(healthPackageService.updateHealthPackage(healthPackage));
    }
}
